package com.njust.controller;

import com.njust.context.BaseContext;
import com.njust.domain.dto.MessageDTO;
import com.njust.domain.dto.MessagePageQueryDTO;
import com.njust.domain.dto.TrainPersonDTO;
import com.njust.domain.dto.UserPageQueryDTO;
import com.njust.domain.vo.PageQueryVO;
import com.njust.result.Result;
import com.njust.service.AdminService;
import com.njust.service.MessageService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @version 1.0
 * @Author Imak
 * @Date 2024/11/7 16:53
 * @管理员
 */
@RestController
@CrossOrigin(origins = "*")
@RequestMapping("/admin")
@Slf4j
public class AdminController {

    @Autowired
    private AdminService adminService;


    /**
     * 分页查询用户
     * @param userPageQueryDTO
     * @return
     */
    @GetMapping("/pageQuery")
    public Result<PageQueryVO> pageQuery(UserPageQueryDTO userPageQueryDTO){
        log.info("用户分页查询，参数为：{}",userPageQueryDTO);
        PageQueryVO PageQueryVO=adminService.pageQuery(userPageQueryDTO);
        return Result.success(PageQueryVO);
    }

    /**
     * 删除用户缓存
     * @param state
     * @param uId
     * @return
     * @throws Exception
     */
    @PostMapping("/state/{state}")
    public Result<String> updateStatus(@PathVariable int state, int uId) throws Exception {
        log.info("更新用户在线状态{}",uId);
        adminService.updateState(state,uId);
        return Result.success("更新状态成功");
    }

    /**
     * 删除账号
     * @return
     */
    @DeleteMapping("/deleteAccount")
    public Result<String> deleteAcc(int uId){
        adminService.deleteAcc(uId);
        log.info("账号已被注销,id={}",uId);
        return Result.success("注销账号成功");

    }






}
